package presentation;

public class PageVO {

    private String pageIndex;

    private String pageSize;

    private int intPageIndex;

    private int intPageSize;

    private int pageNum;

    private int recordNum;

    private int DEFAULT_PAGESIZE;

    public String getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(String pageIndex) {
        intPageIndex = parseInt(pageIndex, 1);
        this.pageIndex = String.valueOf(intPageIndex);
    }

    public String getPageSize() {
        return pageSize;
    }

    public void setPageSize(String pageSize) {
        intPageSize = parseInt(pageSize, DEFAULT_PAGESIZE);
        DEFAULT_PAGESIZE = intPageSize;
        this.pageSize = String.valueOf(intPageSize);
    }

    public int getIntPageIndex() {
        if (pageIndex == null) {
            intPageIndex = 1;
        }
        return intPageIndex;
    }

    public int getIntPageSize() {
        if (pageSize == null) {
            intPageSize = DEFAULT_PAGESIZE;
        }
        return intPageSize;
    }

    public int getPageNum() {
        int d = recordNum / intPageSize;
        int m = recordNum % intPageSize;
        if (d > 0) {
            pageNum = d;
            if (m != 0) {
                pageNum++;
            }
        } else {
            pageNum = 0;
            if (m != 0) {
                pageNum++;
            }
        }
        return pageNum;
    }

    public int getDEFAULT_PAGESIZE() {
        return DEFAULT_PAGESIZE;
    }

    public void setDEFAULT_PAGESIZE(int default_pagesize) {
        DEFAULT_PAGESIZE = default_pagesize;
    }

    public void setRecordNum(int recordNum) {
        this.recordNum = recordNum;
    }

    private static int parseInt(String s, int defaultValue) {
        int ret = defaultValue;
        try {
            ret = Integer.parseInt(s);
        } catch (NumberFormatException e) {
        }
        return ret;
    }

}
